// components/lists/index.js
import {
  HTTP
} from '../../utils/http.js'
let Myhttp = new HTTP()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    questionnaire: Array,
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    my_del:function(e){
      let that = this
      let index = e.currentTarget.dataset.index
      // console.log(index)
      wx.showModal({
        title: '是否提前完成',
        content: '',
        success: function (res) {
          if (res.confirm) {
            that.triggerEvent('my_del', {
              index: index,
            }, {})
          } else if (res.cancel) {
            // console.log('用户点击取消')
          }
        }
      })
      // console.log(index)
    },
    //点击进入问卷具体详情
    container_click: function (e) {
      
      let index = e.currentTarget.dataset.index
      
      this.triggerEvent('lists', {
        index: index,
      }, {})

      let newdatas = this.data.questionnaire[index].id
       newdatas = JSON.stringify(newdatas)
      let isindex = this.data.questionnaire[index].index
      // console.log(newdatas)
      //console.log(this.data.questionnaire[index])

      if(isindex == 1){
        Myhttp.jump({
          url: `/pages/EditFinal/index?datas=${newdatas}`,
        })
       } 
       //else if (isindex == 2){
      //   wx.navigateTo({
      //     url: `/pages/EditFinal/index?datas=${newdatas}`
      //   })
      // }
      

    },
    checkbox:function(e){
      let index = e.currentTarget.dataset.index
      let datas = this.data.questionnaire
      datas[index].checked = !datas[index].checked
      let aa = []
      datas.forEach(val=>{
        if (val.checked){
          aa.push(val.id)
        }
      })
      this.triggerEvent('returnchecked', {
        aa: aa
      }, {})
      //console.log(aa)
    },
  }
})